﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Entities;
namespace WCF_ListenMusic.Services.Module_Comment.Public
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "CommentService" in code, svc and config file together.
    public class CommentService : ICommentService
    {

        Context.Connect_DBDataContext context = new Context.Connect_DBDataContext();
        #region ICommentService Members

        public List<CommentMemberSong> getAllCommentBy_SongID(int SongID)
        {
            try
            {
                if (SongID < 1)
                {
                    throw new FaultException("SongID Nhỏ Hơn 1");
                }
                else
                {
                    var q = from c in context.CommentMemberSongs
                            where c.SongID.Equals(SongID)
                            orderby c.DateComment descending
                            select c;
                    return q.ToList();
                }
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        #endregion


        #region ICommentService Members


        public List<CommentMemberAlbum> getAllCommentBy_AlbumID(int AlbumID)
        {
            try
            {
                if (AlbumID < 1)
                {
                    throw new FaultException("SongID Nhỏ Hơn 1");
                }
                else
                {
                    var q = from c in context.CommentMemberAlbums
                            where c.AlbumID.Equals(AlbumID)
                            orderby c.DateComment descending
                            select c;
                    return q.ToList();
                }
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }

        #endregion
    }
}
